package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.gdms.model.User;
import com.zr.gdms.service.CourseService;
import com.zr.gdms.serviceimpl.CourseServiceImpl;

public class DeleteCourseControllerZYH extends HttpServlet {
	CourseService cs= new CourseServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//设置字符集编码
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		//获取session
		HttpSession session = req.getSession();
		//接收页面传回的值astate,aid
		String appstate = req.getParameter("astate");
		String aid = req.getParameter("aid");
		int appid = Integer.parseInt(aid);
		//获取session中user的数据
		User u = (User) session.getAttribute("user");
		int tid = cs.findTidByUid(u.getUid());
		PrintWriter pw = resp.getWriter();
		
		if(appstate.equals("false")||appstate.equals("审核中")){
			boolean bl = cs.delCourseByAppid(appid);
			if(bl==true){
				pw.write("1");
			}else{
				pw.write("2");
			}
		}else if(appstate.equals("true")){
			pw.write("0");
			
		}
		pw.flush();
		pw.close();
	}
}
